package com.itheima.spring;

import com.itheima.entity.Cart;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.stereotype.Component;

/**
 * FactoryBean 是一个特殊的bean
 * 任何实现了该接口的bean都会在getObject()方法只返回实际的bean对象
 */
@Component
public class MyFactoryBean implements FactoryBean {

    @Override
    public Object getObject() throws Exception {
        return new Cart();
    }

    @Override
    public Class<?> getObjectType() {
        return Cart.class;
    }

    @Override
    public boolean isSingleton() {
        return false;
    }

    public static void main(String[] args) {
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(AppConfig.class);

        System.out.println(applicationContext.getBean("myFactoryBean"));
    }
}
